import api from '../../Sendingmethod/Sendingmethod'
// pages/merchant_revenue/merchant_revenue.js
Page({
    /**
     * 页面的初始数据
     */
    data: {
        showon: false,
        starttime: "",
        endtime: "",
        lodingblen: false,
        listarr: [],
        pageindex: 1,
        allgoal:""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },
    openprop() {
        this.setData({
            showon: true
        })
    },


    addshop(e) {
        console.log(e.detail, '子组件传值');
        if (!e.detail.showblen) {
            console.log('走这里1');
            this.setData({
                showon: false
            })
        } else {
            console.log('走这里2');
            this.setData({
                showon: false,
                starttime: e.detail.datestr.starttime,
                endtime: e.detail.datestr.endtime,
                pageindex: 1
            })
            this.listre()
            this.boxnoe111()
        }

    },
    //列表请求 
    async listre() {
        this.setData({
            lodingblen: true
        })
        let res = await api.myincomelist({
            startTime: this.data.starttime,
            endTime: this.data.endtime,
            page: this.data.pageindex
        })
        console.log('收益列表返回', res);
        if (res.code == 0) {
            setTimeout(() => {
                this.setData({
                    listarr: this.data.pageindex > 1 ? [...this.data.listarr, ...listarr] : res.data.list,
                    lodingblen: false
                })
            }, 1000)
        } else {
            wx.showToast({
                title: res.msg,
                icon: 'error',
                duration: 2000
            })
            this.setData({
                lodingblen: false
            })
        }

    },
    // 总金额 myincometotal
    async boxnoe111() {
        let res = await api.myincometotal({
            startTime: this.data.starttime,
            endTime: this.data.endtime,
        })
        console.log(res,'总金额返回值');
        if(res.code==0){
            this.setData({
                allgoal:res.data.total
            })
        }
    },
    // 触底事件
    Bottomingout() {
        this.data.pageindex = this.data.pageindex + 1
        console.log('触底事件');
        this.listre()
        this.boxnoe111()
    },
        /**
     * xialshuax 下拉刷新
     */
    xialshuax() {
        wx.showLoading({
            mask: true
        })
        console.log('下拉刷新触发');
        // this.getdevicelist(1)
        this.listre()
        setTimeout(() => {
            wx.hideLoading()
            this.setData({
                triggered: false
            })
        }, 1000)
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {


    },
    datachuli(datebox) {
        const timestamp = datebox;
        const date = new Date(timestamp);
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1
        const day = String(date.getDate()).padStart(2, '0');
        const formattedDate = `${year}-${month}-${day}`;
        console.log(formattedDate);
        return formattedDate
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let date = new Date().getTime()
        this.setData({
            starttime: this.datachuli(date),
            endtime: this.datachuli(date)
        })
        this.listre()
        this.boxnoe111()
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})